package helper

import (
	json "github.com/json-iterator/go"
	"github.com/shopspring/decimal"
	"os"
	"time"
)

func MustMarshal(v interface{}) []byte {
	data, _ := json.Marshal(v)
	return data
}

func MustMarshalString(v interface{}) string {
	data, _ := json.MarshalToString(v)
	return data
}

func PathExists(path string) bool {
	_, err := os.Stat(path)
	return err == nil
}

func MTS() int64 {
	return time.Now().UnixNano() / 1000000
}

func NewDecimal(s string) decimal.Decimal {
	num, err := decimal.NewFromString(s)
	if err != nil {
		return decimal.NewFromFloat(0)
	} else {
		return num
	}
}
